<template>
    <div class="address">
        <a-cascader 
            :options="options" 
            @change="onChange" 
            placeholder="请选择地址"
            :defaultValue="defaultAddress">
            <a-icon type="home" slot="suffixIcon" class="test"/>
        </a-cascader>
        <a-input placeholder="详细地址" v-if="detailAddress" @change="changeAddress" :defaultValue="address"/>
    </div>
</template>
<script>
import addressValue from '@/units/addressValue'
import allAddressValue from '@/units/allAddressValue'
export default {
    name:'eAddress',
    props:{
        defaultAddress:Array,
        detailAddress:{type:Boolean,default:false},
        isAllAddress:{type:Boolean,default:false}
    },
    created(){
        this.options=this.isAllAddress?allAddressValue:addressValue
        this.addressInfo=this.defaultAddress
        this.address=this.defaultAddress[3]
    },
    data(){
        return{
            options:null,
            addressInfo:null,
            address:''
        }
    },
    methods:{
        onChange(val){
            this.addressInfo=val
            this.$emit('changeAddress',this.addressInfo)
        },
        changeAddress(data){
            this.addressInfo[3]=data.target.value
            this.$emit('changeAddress',this.addressInfo)
        }
    }

}
</script>